package visualizer.drawable;

import java.util.Map;

import visualizer.drawable.transition.TransitionFactory;

public class TransitioningDrawableSwitcher<T> extends DrawableSwitcher<T> {
	private TransitionFactory defaultTransitionFactory;
	
	public TransitioningDrawableSwitcher(Map<T, Drawable> drawables, TransitionFactory defaultTransitionFactory) {
		super(drawables);
		this.defaultTransitionFactory = defaultTransitionFactory;
	}
	
	public DrawableSwitcher<T> setSelectedKey(T selected) {
		return setSelectedKey(selected, defaultTransitionFactory);
	}

	
	public DrawableSwitcher<T> setSelectedKey(T selected, TransitionFactory transition) {
		Drawable from = getSelectedDrawable();
		Drawable to = getDrawable(selected);
		if ((from != null) && (to != null) && (!from.equals(to))) {
			setDrawable(selected, transition.create(from, to));
		}
		
		return super.setSelectedKey(selected);
	}
}
